package br.siseventos.util;

import java.io.*;
import javax.servlet.ServletContext;
import org.primefaces.model.UploadedFile;

public class FileUploadHelper {
    private static ConfigHelper conf;
    static
    {
        try {
            conf = new ConfigHelper("app.properties");
        } catch (IOException ex) {
        }
    }
    
    
    public static void saveImage(UploadedFile file, ServletContext context) {
        String newFileName = context.getRealPath(conf.getProperty("pathImageStore")) + "/" +  file.getFileName();
        try {
            FileOutputStream fos = new FileOutputStream(new File(newFileName));
            InputStream is = file.getInputstream();
            byte[] b = file.getContents();
            fos.write(b);            
            fos.close();
            is.close();
        } catch (IOException e) {
        }
    }
}
